package com.example.eventdemo.listener;

import com.example.eventdemo.entity.UserMessage;
import com.example.eventdemo.event.NoticeEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 邮件服务监听器
 * 监听用户注册事件，发送欢迎邮件
 */
@Component
@Slf4j // Lombok日志注解
public class EmailListener {

    @EventListener // 标记为事件监听器
    public void handleUserRegisterEvent(NoticeEvent event) {
//        Message user = event.getUser();
//        log.info("给用户[{}]发送欢迎邮件，邮箱：{}", user.getUsername(), user.getEmail());
        // 实际项目中这里会调用邮件发送API

        UserMessage user = event.getUser();
        Object source = event.getSource();
        if (user.getType().equals("type1")) {
            System.out.println(user + "---" + source);
        }
    }
}